package motionControl;

import javax.swing.JFrame;

import com.leapmotion.leap.Controller;
import com.leapmotion.leap.Frame;
import com.leapmotion.leap.Hand;
import com.leapmotion.leap.InteractionBox;
import com.leapmotion.leap.Vector;

public class Ball extends JFrame {

	static int width = 1400;
	static int height = 800;
	Fenster fenster;
	Position position;
	
	public Ball() {
		fenster = new Fenster(width, height);
		position = new Position(width, height);
		this.setTitle("Leap Motion");
		this.setSize(width, height);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setContentPane(fenster);
		this.setVisible(true);
		Controller leap = new Controller();
		
		
		while (true) {
			
			Frame frame = leap.frame();
			InteractionBox ibox = leap.frame().interactionBox();
			Hand hand = frame.hands().get(0);
			Vector normHand = ibox.normalizePoint(hand.palmPosition());
			int x = (int) (normHand.getX() * 1400);
			int y = (int) (800 - normHand.getY() * 800);
			HandRegistry h = new HandRegistry(x, y);
			
			position.setCalculate(h);
			position.calculate();

			fenster.setPosition(h);
			fenster.repaint();
			try {
				Thread.currentThread().sleep(20);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
}
